package com.example.rxjava;

import rx.Observable;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.schedulers.Schedulers;


/**
 * subscribeOn() 和 observeOn()
 *
 * 这两个方法是rxjava 最重要的两个指定线程的方法，subscribeOn表示上游生产者的所处线程，observeOn()表示下游消费者所处线程，我们可以通过传递一个Scheduler类型的参数给这两个方法，分别指定上下游所处线程，在Schedulers，这个工具类定义了5个线程类型
 *
 *
 * Observable常用知识点整理： https://blog.csdn.net/qq_32530561/article/details/102541223
 *
 */
public class RxTest01 {
    public static void main(String[] args) {
        /*Observable.just("1").doOnSubscribe(
                ()-> System.out.println("1 " +Thread.currentThread().getName() )

        ).subscribeOn(Schedulers.io()).observeOn(Schedulers.computation()).toBlocking().subscribe(
                i-> System.out.println("2 "+ Thread.currentThread().getName())
        );*/


        /**
         * https://juejin.cn/post/6844903682685796365
         *
         * doOnSubscribe
         * doOnNext hello
         * subscribe hello
         * doOnNext w3cschool
         * subscribe w3cschool
         * doOnNext com
         * subscribe com
         * doAfterTerminate
         */
        /*Observable.just("hello","w3cschool","com").doOnSubscribe(new Action0() {
            @Override
            public void call() {
                System.out.println("doOnSubscribe");
            }
        }).doAfterTerminate(new Action0() {
            @Override
            public void call() {
                System.out.println("doAfterTerminate");
            }
        }).doOnError(new Action1<Throwable>() {
            @Override
            public void call(Throwable throwable) {
                System.out.println("doOnError " + throwable.getMessage());
            }
        }).doOnNext(new Action1<String>() {
            @Override
            public void call(String s) {
                System.out.println("doOnNext "+ s);
            }
        }).subscribe(new Action1<String>() {
            @Override
            public void call(String s) {
                System.out.println("subscribe "+ s);
            }
        });*/

        //Observable.just("hello","jjj").flatMap(item->Observable.just(item+"world")).flatMap(item->Observable.just(item+"fff")).map(item->item.toUpperCase()).subscribe(s-> System.out.println(s));

    }
}
